package com.ncmmall.api.security.interceptor;

import cn.hutool.core.util.StrUtil;
import com.feijin.commons.lang.PropertiesHelps;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;


/**
 * @author linxs
 *         权限路径配置器
 */
@Component
public class WebConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        String content = PropertiesHelps.getValue("api-access-anon");

        List<String> paths = StrUtil.splitTrim(content, ";");

        paths.add("/wechat/**/*");
        paths.add("/wechat/pay/alipay/**/callback");
        paths.add("/wechat/pay/app/**/callback");

        String[] anons = new String[paths.size()];
        paths.toArray(anons);

        registry.addInterceptor(new AuthorizationInterceptor()).addPathPatterns("/*", "/**", "/**/**").excludePathPatterns(anons);
    }
}
